<template>
  <div>
    <avue-form :key="actFormKey"
               ref="avueForm"
               :option="actFormOption"
               v-model="actFormModel"
               @submit="submitForm"></avue-form>
  </div>

</template>

<script>
import startActFormApi from "@/api/start/activiti/core/startActFormApi";
import startActFormTools from "../startActFormTools";

export default {
  name: "actTaskForm",
  props: {
    formBtn: {
      type: Boolean,
      default: true,
    },
    formConfig: {
      type: Object,
      required: true,
    },
    formModel: {
      type: Object,
      required: true,
    },
    isDetail: {
      type: Boolean,
      default: true,
    }
  },
  data() {
    return {
      actFormKey: Math.random(),
      actFormModel: this.formModel,
      actFormOption: {menuBtn: false},
    }
  },
  created() {
    startActFormApi.getActFormOption(this.formConfig.id).then(this.analysisForm)
  },
  methods: {
    analysisForm(res) {
      let data = res.data.data;
      data.menuBtn = false;
      data.detail = this.isDetail;
      startActFormTools.autoActTaskForm(data)
      this.actFormOption = data;
    },
    submit() {
      this.$refs.avueForm.submit();
    },
    resetForm() {
      this.$refs.avueForm.resetForm();
    },
    submitForm(data, done) {
      data.businessKey = "";
      let formData = {};
      for (const key in data) {
        if (key.startsWith("$")) {
          continue
        }
        formData[key] = data[key];
      }
      this.$emit("submit", formData, done)
    },

  }
}
</script>

<style scoped>

</style>
